home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 2 / Mac Magazin and MacEasy Magazine CD - Issue 02.iso / Sharewarebibliothek / Applikationen / Alpha.5.81 folder / Tcl / UserCode / reverseLines.tcl < prev    next >
Text File  |  1994-03-08  |  2KB  |  69 lines

  1. # FILE: reverseLines.tcl
  2. #
  3. # LAST UPDATE: 01/06/93 5:23:08 AM
  4. #
  5. # This file contains the following TCL procedure(s):
  6. #
  7. #    reverseLines -- Reverses the order a selection of lines of text
  8. #
  9. #    To use, simply source this file place it in the a folder with the
  10. #    name $HOME:Tcl:Usercode: and invoke it implicitly via the "unknown proc".
  11. #
  12. # SEE ALSO unknown.tcl
  13.  
  14. # COPYRIGHT:
  15. #
  16. #    Copyright © 1992,1993 by David C. Black
  17. #    All rights reserved.
  18. #
  19. #    Redistribution and use in source and binary forms are permitted
  20. #    provided that the above copyright notice and this paragraph are
  21. #    duplicated in all such forms and that any documentation,
  22. #    advertising materials, and other materials related to such
  23. #    distribution and use acknowledge that the software was developed
  24. #    by David C. Black.
  25. #
  26. #    THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
  27. #    IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  28. #    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  29. #
  30. ################################################################################
  31.  
  32. # AUTHOR
  33. #
  34. #    David C. Black
  35. #    Internet: black@mpd.tandem.com (preferred)
  36. #    GEnie:    D.C.Black
  37. #    USnail:   6217 John Chisum Lane, Austin, TX 78749
  38. #
  39. ################################################################################
  40.  
  41. # HISTORY
  42. #                  
  43. # modified who rev reason
  44. # -------- --- --- ------
  45. # 01/06/93 DCB 1.0 Original
  46.  
  47. proc reverseLines {} {
  48.     set end  [selEnd]
  49.     set start [getPos]
  50.     if {$start == $end} {
  51.         alertnote "You must highlight the section you wish to reverse."
  52.         return
  53.     }
  54.     if {[lookAt [expr $end-1]] != "\r"} {
  55.         alertnote "The selection must consist only of complete lines."
  56.         return
  57.     }
  58.     set text [split [getText $start [expr {$end-1}]] "\r"]
  59.     set i [llength $text]
  60.     while {$i > 0} {
  61.         incr i -1
  62.         lappend reversed [lindex $text $i]
  63.     }
  64.     #endwhile
  65.     set text [join $reversed "\r"]
  66.     replaceText $start [expr {$end-1}] $text
  67.     select $start $end
  68. }
  69.